package T16_生成资源列表;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;

import java.io.File;
import java.io.FileFilter;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        //扫描目录下的所有文件，然后放入到资源列表当中
        String projectPath = "D:\\MyWorkspace\\Java\\ag-app-res\\ag-apps\\创造与魔法";

        String projectName = FileUtil.getName(projectPath);
        List<File> files = FileUtil.loopFiles(projectPath, new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                //去除所有的js代码文件
                return !StrUtil.endWithAnyIgnoreCase(pathname.getName(), ".js");
            }
        });
        StringBuilder sbResList = new StringBuilder();
        for (File file : files) {
            String androidResPath = "/sdcard/Pictures/" + projectName + StrUtil.addPrefixIfNot(StrUtil.replace(StrUtil.replace(StrUtil.subAfter(file.getAbsolutePath(), projectName, true), "\\", "/"), "\\\\", "/"), "/");
            sbResList.append(androidResPath).append("\n");
        }
        File file_res = new File(projectPath, "res");
        File file_aigame = new File(file_res, "aigame");
        File file_aigame_list = new File(file_aigame, "list.txt");
        FileUtil.writeUtf8String(sbResList.toString(), file_aigame_list);
        System.out.println(sbResList);
    }
}
